package com.back.controller;

import com.back.domain.VO.R;
import com.back.domain.VO.SYSTEM.SysUserPagingBody;
import com.back.enums.CodeEnum;
import com.back.service.SysDeptService;
import com.back.service.SysUserService;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/sysUser")
//    用户管理界面
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private SysDeptService sysDeptService;
//    获取用户列表
    @GetMapping("/getList")

    public R GetList(@RequestBody SysUserPagingBody sysUserPagingBody){
//        为页数和条数添加默认值
        if (sysUserPagingBody.getPageSize()==null||sysUserPagingBody.getPageNum()==null) {
            // 设置默认值
            sysUserPagingBody.setPageNum(1);
            sysUserPagingBody.setPageSize(10);
        }
            sysUserPagingBody.setLimit(sysUserPagingBody.getPageSize());
            sysUserPagingBody.setOffset((sysUserPagingBody.getPageNum()-1)* sysUserPagingBody.getPageSize());

        Map<String, Object> data = sysUserService.sysUserGetAll(sysUserPagingBody);
        return new R(CodeEnum.GET_SUCCESS.getCode(), CodeEnum.GET_SUCCESS.getMsg(),data);
    }
//    获取左侧结构树
@GetMapping("/getTree")
    public R GetTree() throws JsonProcessingException {
        return new R(CodeEnum.GET_SUCCESS.getCode(), CodeEnum.GET_SUCCESS.getMsg(),sysDeptService.buildTree());
    }
}
